package com.jlnk.androidfmc.entity;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

public class Product implements Parcelable {
    private String id;
    private String name;
    private String description;
    private String imagePath;
    private int categoryId; // 分类ID，作为外键引用
    private double price;
    public static final Creator<Product> CREATOR = new Creator<Product>() {
        @Override
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        @Override
        public Product[] newArray(int size) {
            return new Product[size];
        }
    };

    private Product(Parcel in) {
        id = in.readString();
        name = in.readString();
        description = in.readString();
        imagePath = in.readString();
        categoryId = in.readInt();
        price = in.readDouble();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(id);
        dest.writeString(name);
        dest.writeString(description);
        dest.writeString(imagePath);
        dest.writeInt(categoryId);
        dest.writeDouble(price);
    }
    // 默认构造函数
    public Product() {
    }

    // 带参数的构造函数
    public Product(String id, String name, String description, String imagePath, int categoryId, double price) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.imagePath = imagePath;
        this.categoryId = categoryId;
        this.price = price;
    }

    // id的getter和setter
    public String getId() {
        return id;
    }

    public void setId(String id) { // 确保这里接受的是String类型的参数
        this.id = id;
    }

    // name的getter和setter
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    // description的getter和setter
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    // imagePath的getter和setter
    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    // categoryId的getter和setter
    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    // price的getter和setter
    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    // toString方法，方便打印对象信息
    @Override
    public String toString() {
        return "Product{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", imagePath='" + imagePath + '\'' +
                ", categoryId=" + categoryId +
                ", price=" + price +
                '}';
    }
}